//=============================================================================
// Tripmines beam of fire
//=============================================================================
class ClawFireMineBlast extends Emitter;

var vector Direction;

replication
{
	reliable if ( Role == ROLE_Authority )
		Direction;
}

// shameless copying/pasting from Engine.Projectile - Wormbo

//-----------------------------------------------------------------------------
// Projectile variables.

// Motion information.
var float Speed;              // Initial speed of projectile.

// Damage attributes.
var float Damage;
var float MomentumTransfer;   // Momentum magnitude imparted by impacting projectile.
var class<DamageType> MyDamageType;
var Controller InstigatorController;

// explosion effects
var class<Projector> ExplosionDecal;

//==============
// Touching
simulated singular function Touch(Actor Other)
{
	local actor HitActor;
	local vector HitLocation, HitNormal, VelDir;
	local bool bBeyondOther;
	local float BackDist, DirZ;

	if ( Other == None ) // Other just got destroyed in its touch?
		return;
	if ( Other.bProjTarget || Other.bBlockActors && Other.bBlockPlayers ) {
		if ( Velocity == vect(0,0,0) || Other.IsA('Mover') ) {
			ProcessTouch(Other, Location);
			return;
		}

		//get exact hitlocation - trace back along velocity vector
		bBeyondOther = Velocity Dot (Location - Other.Location) > 0;
		VelDir = Normal(Velocity);
		DirZ = sqrt(VelDir.Z);
		BackDist = Other.CollisionRadius * (1 - DirZ) + Other.CollisionHeight * DirZ;
		if ( bBeyondOther )
			BackDist += VSize(Location - Other.Location);
		else
			BackDist -= VSize(Location - Other.Location);

	 	HitActor = Trace(HitLocation, HitNormal, Location, Location - 1.1 * BackDist * VelDir, true);
		if ( HitActor == Other )
			ProcessTouch(Other, HitLocation);
		else if ( bBeyondOther )
			ProcessTouch(Other, Other.Location - Other.CollisionRadius * VelDir);
		else
			ProcessTouch(Other, Location);
	}
}

simulated function ProcessTouch(Actor Other, Vector HitLocation)
{
	if ( MyDamageType.Default.bDelayedDamage && Instigator == None && Pawn(Other) != None )
		Pawn(Other).DelayedDamageInstigatorController = InstigatorController;
	if ( Pawn(Other) == None || Other.ROLE == ROLE_Authority )
		Other.TakeDamage(Damage, Instigator, HitLocation, MomentumTransfer * Normal(Velocity), MyDamageType);
}

simulated function HitWall (vector HitNormal, actor Wall)
{
	if ( Wall.Role == ROLE_Authority && Mover(Wall) != None )
		Wall.TakeDamage(Damage, Instigator, Location, MomentumTransfer * Normal(Velocity), MyDamageType);

	SetPhysics(PHYS_None);
	Kill();
	if ( ExplosionDecal != None && Level.NetMode != NM_DedicatedServer )
		Spawn(ExplosionDecal, Self,, Location, rotator(-HitNormal));
}

simulated function PostBeginPlay()
{
	Velocity = vector(Rotation) * Speed;
	Direction = Velocity;
	SetTimer(2.5, false);
}

simulated function PostNetBeginPlay()
{
	Velocity = Direction;
}

simulated event PhysicsVolumeChange(PhysicsVolume NewVolume)
{
	if ( NewVolume.bWaterVolume )
		Timer();
}

simulated function Timer()
{
	Kill();
	Disable('Touch');
	SetTimer(0.0, False);
}

defaultproperties
{
     Speed=1400.000000
     Damage=30.000000
     MomentumTransfer=5000.000000
     MyDamageType=Class'taskforces.DamTypeClawFiremineFire'
     Begin Object Class=SpriteEmitter Name=SpriteEmitter0
         FadeOut=True
         FadeIn=True
         SpinParticles=True
         UseSizeScale=True
         UseRegularSizeScale=False
         UniformSize=True
         UseSubdivisionScale=True
         UseRandomSubdivision=True
         FadeOutStartTime=0.200000
         FadeInEndTime=0.100000
         MaxParticles=200
         SpinsPerSecondRange=(X=(Min=-0.300000,Max=0.300000))
         StartSpinRange=(X=(Max=5000.000000),Y=(Max=5000.000000),Z=(Max=5000.000000))
         SizeScale(0)=(RelativeSize=0.300000)
         SizeScale(1)=(RelativeTime=0.500000,RelativeSize=3.000000)
         SizeScale(2)=(RelativeTime=2.000000,RelativeSize=3.000000)
         StartSizeRange=(X=(Min=10.000000,Max=10.000000),Y=(Min=10.000000,Max=10.000000),Z=(Min=10.000000,Max=10.000000))
         Texture=Texture'EmitterTextures.MultiFrame.LargeFlames'
         TextureUSubdivisions=4
         TextureVSubdivisions=4
         LifetimeRange=(Min=0.500000,Max=1.000000)
         StartVelocityRange=(X=(Min=10.000000,Max=-10.000000),Y=(Min=10.000000,Max=-10.000000),Z=(Min=10.000000,Max=-10.000000))
         GetVelocityDirectionFrom=PTVD_AddRadial
         WarmupTicksPerSecond=1.000000
         RelativeWarmupTime=1.000000
     End Object
     Emitters(0)=SpriteEmitter'taskforces.ClawFiremineBlast.SpriteEmitter0'

     bNoDelete=False
     bNetTemporary=True
     bAlwaysRelevant=True
     Physics=PHYS_Projectile
     RemoteRole=ROLE_SimulatedProxy
     AmbientSound=Sound'TFMedia.Lasermine.lasermine_woosh'
     LifeSpan=4.000000
     SoundVolume=255
     SoundRadius=100.000000
     CollisionRadius=0.000000
     CollisionHeight=0.000000
     bCollideActors=True
     bCollideWorld=True
}
